import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * Classe que controla um socket de cliente
 * 
 */
public class ControllerClient {
	
	private Socket sock;
    private PrintWriter pout;
    private BufferedReader in;
    
    public ControllerClient(String ip, int porta){
    	try{
    		sock = new Socket(ip, porta);
    		pout = new PrintWriter(sock.getOutputStream(), true);
    		in =  new BufferedReader(new InputStreamReader(sock.getInputStream()));
    	}catch (IOException e) {
    		System.out.println("Could not connect to the server");
		}
    	
    }

    //Le um int no socket
    public int readInt(){
    	String temp;
    	try{
    		
    		temp = in.readLine();	
    	
    	}catch (IOException e) {
    		return -1;
    	}
    	return Integer.parseInt(temp);
    }    

    //Escreve um int no socket
    public void writeInt(int i){
        pout.println(i);
        
    }
	
    //Escreve uma string no socket
    public void enviaString(String s){
        pout.println(s);    
    }
    
    
    //Le uma string do socket
	public String leString(){
		try {
			return in.readLine();
		} catch (IOException e) {
			return "";
		}
	}

    
}
